package com.univrz.flexmachine.scmxml.v
{
	
	
	import com.univrz.flexmachine.scxml.model.SCXMLModelObject;
	import com.univrz.flexmachine.scxml.model.TransitionEdge;
	
	import mx.containers.Tile;
	import mx.controls.Label;
	import mx.utils.StringUtil;

/**
 *  
 * 
 *  @eventType com.univrz.flexmachine.events.StateMachineEvent.FIRE
 */
[Event(name="fire", type="com.univrz.flexmachine.events.StateMachineEvent")]	




	public class Transition extends Tile
	{
		

		
		[Bindable]
		public var transitionEdge:TransitionEdge;
		
		
		
		private var button:Label;
		
		


	    //----------------------------------
	    //  event
	    //----------------------------------
	    [Inspectable(category="FlexMachine", name="Event")]	
	    [Bindable]
		public var event:*;
		
		
		

	    //----------------------------------
	    //  cond
	    //----------------------------------
	    [Inspectable(category="FlexMachine", name="Condition")]
	    [Bindable]		
		public var cond:*;		





	    //----------------------------------
	    //  target
	    //----------------------------------
	    [Inspectable(category="FlexMachine", name="Target")]
	    [Bindable]			
		public var target:*;
		
		
		
		
		
		
		private var labels:Array = [];		
		
		
		
		public function Transition( )
		{
		
			super( );
			
			mouseChildren = false;
			mouseEnabled = false;
			
			percentWidth = 100;
		}
		

		
		public function setModelObject( mobj:SCXMLModelObject ):void
		{
			// TransitionEdge model object
			transitionEdge = mobj as TransitionEdge;
		}
		
		
		
		private function updateText( ):void
		{

			setText( [ event , cond, target ] );

		}
		
		
		private function setText( textArr:Array ):void
		{
			for ( var i:int=0; i<textArr.length; i++ )
				( getChildAt( i ) as Label ).text = textArr[i] as String;
		
		}
		
		
		override protected function createChildren( ):void
		{
			
			super.createChildren( );
			
			if ( labels.length==0 )
			{

				
				
				
				for ( var i:int=0; i<3; i++ )
				{
					var label:Label = new Label( );
					label.setStyle( "fontSize", 7 );
					labels.push( label );
					addChild( label );
				}
			
				updateText( );
				
			}
			
		
		}
		
		
		
		override protected function commitProperties( ):void
		{
			super.commitProperties( );
			updateText( );
			invalidateDisplayList( );
		}
		
		
		
		
		
		
				
		
	}
	
	
}
